package com.run.motion.controller;

import java.util.List;

import com.run.motion.entity.Comment;
import com.run.motion.service.ICommentService;
import com.run.motion.util.page.AjaxResult;
import com.run.motion.util.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 评论Controller
 * 
 * @author lyq
 * @date 2022-03-26
 */
@Api(tags = "评论")
@RestController
@RequestMapping("/comment")
public class CommentController extends BaseController
{
    @Autowired
    private ICommentService commentService;

    /**
     * 查询评论列表
     */
    @ApiOperation(value = "评论列表")
    @GetMapping("/list")
    public TableDataInfo list(Comment comment)
    {
        startPage();
        List<Comment> list = commentService.selectCommentList(comment);
        return getDataTable(list);
    }


//    /**
//     * 获取评论详细信息
//     */
//    @GetMapping(value = "/{pid}")
//    public AjaxResult getInfo(@PathVariable("pid") Long pid)
//    {
//        return AjaxResult.success(commentService.selectCommentByPid(pid));
//    }

    /**
     * 根据mid获取评论详细信息
     */
    @ApiOperation(value = "根据mid获取评论详细信息")
    @GetMapping(value = "/{mid}")
    public AjaxResult getMidInfo(@PathVariable("mid") Long mid)
    {
        return AjaxResult.success(commentService.selectCommentByMidList(mid));
    }

    /**
     * 新增评论
     */
    @ApiOperation(value = "新增评论")
    @PostMapping
    public AjaxResult add(@RequestBody Comment comment)
    {
        return toAjax(commentService.insertComment(comment));
    }

    /**
     * 修改评论
     */
    @ApiOperation(value = "修改评论")
    @PutMapping
    public AjaxResult edit(@RequestBody Comment comment)
    {
        return toAjax(commentService.updateComment(comment));
    }

    /**
     * 删除评论
     */
    @ApiOperation(value = "删除评论")
	@DeleteMapping("/{pids}")
    public AjaxResult remove(@PathVariable Long[] pids)
    {
        return toAjax(commentService.deleteCommentByPids(pids));
    }
}
